home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 280_01 / kwic.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-11  |  2.3 KB  |  103 lines

  1. /* [KWIC.C of JUGPDS Vol.46] */
  2. /*
  3. *****************************************************************
  4. *                                *
  5. *    Written by  Hakuo Katayose (JUG-CP/M No.179)        *
  6. *            49-114 Kawauchi-Sanjuunin-machi        *
  7. *            Sendai, Miyagi 980                          *
  8. *            Phone: 0222-61-3219                *
  9. *                                *
  10. *       Modifird by Toshiya Oota   (JUG-CPM No.10)              *
  11. *                   Sakae ko-po 205                 *
  12. *            5-19-6 Hosoda                *
  13. *            Katusikaku Tokyo 124            *
  14. *                                *
  15. *        for MS-DOS Lattice C V3.1J & 80186/V20/V30    *
  16. *                                *
  17. *    Compiler Option: -ccu -k0(1) -ms -n -v -w        *
  18. *                                *
  19. *    Edited & tested by Y. Monma (JUG-CP/M Disk Editor)    *
  20. *            &  T. Ota   (JUG-CP/M Sub Disk Editor)    *
  21. *                                *
  22. *****************************************************************
  23. */
  24.  
  25. /* kwic - make keyword in context index */
  26.  
  27. #include "stdio.h"
  28. #include "dos.h"
  29. #include "tools.h"
  30. #include "toolfunc.h"
  31.  
  32. #define    FOLD    36    /* FOLD = '$' */
  33.  
  34. int    cc;
  35. char    fold;
  36.  
  37. void putrot(),rotate(),putchr();
  38.  
  39. void main(argc, argv)
  40. int    argc;
  41. char     **argv;
  42. {
  43. char    buf[MAXLINE];
  44. char    *ap;
  45.     fold = FOLD;
  46.     while (--argc > 0) {
  47.     if ((*++argv)[0] == '-')
  48.         for (ap = (*argv)+1; *ap != NULL; ap++) {
  49.         if (tolower(*ap) == 'f') {
  50.             if(*(ap+1) != NULL)
  51.             fold = *(++ap);
  52.             else 
  53.             error("KWI901 Do specify FOLD char");
  54.         }
  55.         else
  56.             error("KWI999 Usage: kwic [-fFOLD] <infile >outfile");
  57.         }
  58.     }
  59.     cc = 'a';
  60.     while (getlin(buf, MAXLINE) > 0)
  61.     putrot(buf);
  62. }
  63.  
  64. /* putrot - create lines with keyword at front */
  65. void putrot(buf)
  66. char buf[];
  67. {
  68. int    i, t;
  69.     for (i = 0; buf[i] != NEWLINE; i++) {
  70.     t = type(buf[i]);
  71.     if (t == LETTER || t == DIGIT) {
  72.         rotate(buf, i);
  73.         t = type(buf[i+1]);
  74.         for (; t == LETTER || t == DIGIT; t = type(buf[i+1]))
  75.         i++;
  76.     }
  77.     }
  78. }
  79.  
  80.  
  81. /* rotate - output rotated line */
  82. void rotate(buf, n)
  83. char buf[];
  84. {
  85. int    i;
  86.     for (i = n; buf[i] != NEWLINE; i++)
  87.     putchr(buf[i]);
  88.     putchr(fold);
  89.     for (i = 0; i < n; i++)
  90.     putchr(buf[i]);
  91.     putchr(NEWLINE);
  92. }
  93.  
  94. void putchr(c)
  95. int    c;
  96. {
  97.     if (c == '\t')
  98.     c = BLANK;
  99.     if (c != BLANK || cc != BLANK)
  100.     putchar(c);
  101.     cc = c;
  102. }
  103.